<!-- 选择户号 -->
<template>
	<uni-popup ref="userinfoselectpopup" background-color="#fff" type="bottom" :mask-click="false">
		<view class="userinfoselect-dom">
			<view class="p40">
				<uni-row class="demo-uni-row ">
					<uni-col :span="14" :offset="5">
						<view class="userinfoselect-dom-title">请选择</view>
					</uni-col>
				<uni-col :span="5">
					<view class="t-r">
						<uni-icons @click="cancelClick" type="closeempty" size="15" class="p20"></uni-icons>
					</view>
					</uni-col>
				</uni-row>
			</view>
			<scroll-view class="contentshow" scroll-y :show-scrollbar='true' :enhanced='true'>
				<uni-list v-if="yhbhList.length" class="userinfoselect-list" :avatar-circle="true">
					<uni-list-item v-for="item in yhbhList" direction="column" clickable   @click="setYhbh(item.yhbh)">
						<template v-slot:header>
							<view class="userinfoselec-title">
								<text>户号：</text>
								<text>{{item.yhbh}}</text>
							</view>
							<view class="userinfoselec-describe">
								<text>名称：</text>
								<text>{{item.yhmc}}</text>
							</view>
							<view class="userinfoselec-describe">
								<text>地址：</text>
								<text>{{item.yhdz}}</text>
							</view>
						</template>
					</uni-list-item>
				</uni-list>
			</scroll-view>
		</view>
	</uni-popup>
</template>

<script setup lang="ts">
	import { getPhone } from "@/utils/storage";
	import { HlwYxyh } from "@/api/tables/HlwYxyh";
	import { GetHuHaoByPhone } from "@/api/request/GetHuHaoByPhone";
	import { ref, onMounted, defineEmits  } from "vue"
	const emit = defineEmits(['setYhbh'])
	let yhbhList = ref<Array<HlwYxyh>>([]);
	let userinfoselectpopup = ref();
	
	onMounted(() => {
		getListData()
	})
	function getListData() {
		GetHuHaoByPhone({
			data: { dlzh: getPhone(), bdzt: "0" },
			success: (res) => {
				if (res.length == 0) {
					uni.showModal({title: "提示", content: "当前用户无绑定的电用帐号，无法进行下一步操作！", showCancel: false })
					uni.navigateBack() // 返回
				} else if (res.length == 1) {
					setYhbh(res[0].yhbh)
				} else {
					yhbhList.value = res
					userinfoselectpopup.value.open()
				}
			},
			fail: (_code, message) => {
				uni.showModal({ content: message, showCancel: false })
				uni.navigateBack()
			}
		})
	}
	function setYhbh(yhbh: string){
		userinfoselectpopup.value.close()
		emit('setYhbh', yhbh)
	}
	function cancelClick(){
		uni.navigateBack()
	}
</script>

<style lang="scss">
	.userinfoselect-dom-title{
		color: #3b4144;
		font-size: 30rpx;
		text-align: center;
	}
	
	.contentshow{
		max-height: 80vh;
	}
	.userinfoselec-title {
		line-height: 1.8;
		color: #3b4144;
		font-size: 28rpx;
	}

	.userinfoselec-describe {
		line-height: 1.8;
		color: #999;
		font-size: 24rpx;

	}
</style>